﻿
// ———————————————————————–
// <copyright file="TestObject.cs" company="The MITRE Corporation">
//    Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//    http://www.apache.org/licenses/LICENSE-2.0
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
// </copyright>
// ———————————————————————–
/////////////////////////////////////////////////////////////////////////////////////////////////
// TestObject.cs:
//
// A generic object used to hold testing information.
//
// Project: NIEMCADTest
// Author:  Lizzie DeYoung - MITRE
/////////////////////////////////////////////////////////////////////////////////////////////////

// Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//
// NOTICE
// This software was produced for the U. S. Government
// under Contract No. FA8721-09-C-0001, and is
// subject to the Rights in Noncommercial Computer Software
// and Noncommercial Computer Software Documentation Clause
// (DFARS) 252.227-7014 (JUN 1995)  
      
using EDXLSharp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Xml;

namespace NIEMCADTest
{
  /// <summary>
  /// To enable abstracted processing of each data type, the information about the data type is stored 
  /// in a test object. The test object includes:
  /// - [Obj] a reference to the data type using the abstract type ComplexTypeBase that all of the data 
  /// types in the NIEM libraries inherit from
  /// - [Xml] An XmlNode containing the parsed XML of the good or bad XML representation for the data
  /// type
  /// - [TestParameters] A dictionary containing the name of the value to test and the expected value
  /// - [Children] This is currently not used, but may be helpful for managing recursive validation.
  /// The TestObject also includes a GOOD_READ_Validation() method that checks that the expected 
  /// namespace, name, and prefix all match the resulting namespace, name, and prefix. Because this
  /// test is necessary for all data types, it is abstracted out to here.
  /// </summary>
  public class TestObject
  {
    public const string NAMESPACE = "namespace";
    public const string NAME = "name";
    public const string PREFIX = "prefix";

    public List<TestObject> Children { get; private set; }
    public XmlNode Xml { get; set; }
    public ComplexTypeBase Obj { get; set; }
    public Dictionary<string, string> TestParameters { get; private set; }

    public TestObject()
    {
      Children = new List<TestObject>();
      Xml = null;
      Obj = null;
      TestParameters = new Dictionary<string, string>();
    }

    public TestObject(string elementNamespace, string elementName, string elementPrefix)
    {
      Children = new List<TestObject>();
      Xml = null;
      Obj = null;
      TestParameters = new Dictionary<string, string>();

      TestParameters.Add(NAMESPACE, elementNamespace);
      TestParameters.Add(NAME, elementName);
      TestParameters.Add(PREFIX, elementPrefix);
    }

    public void GOOD_READ_Validation()
    {
      if (TestParameters.ContainsKey(NAMESPACE))
      {
        Assert.AreEqual(TestParameters[NAMESPACE], Obj.ElementNamespace);
      }
      if (TestParameters.ContainsKey(NAME))
      {
        Assert.AreEqual(TestParameters[NAME], Obj.ElementName);
      }
      if (TestParameters.ContainsKey(PREFIX))
      {
        Assert.AreEqual(TestParameters[PREFIX], Obj.ElementPrefix);
      }
    }
  }
}
